﻿using B.S.BasicData.API.Read.Application.Command.Leave;
using B.S.BasicData.API.Read.DTOS.Leave;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.API.Read.Controllers
{
    /// <summary>
    /// 申请控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class LeaveController : ControllerBase
    {
        IMediator mediator;

        public LeaveController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取申请类别
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<LeaveTypeDTO>>> GetLeaveType([FromQuery]GetLeaveTypeCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 获取申请列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<LeaveDTO>> GetMyLeave([FromQuery]GetMyLeaveCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 获取员工请假报表数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<LeaveReportDTO>> GetLeaveReport([FromQuery]GetLeaveReportCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查看个人在某个月的请假信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<LeaveDTO>>> GetLeavePresonData([FromQuery]GetLeavePresonDataCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }


    }
}
